home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / source / show.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-22  |  2.4 KB  |  121 lines

  1. /*
  2.  *  SHOW.C -- Show data
  3.  *
  4.  *  Copyright (C) 1991 by Jarkko Vuori. All rights reserved.
  5.  *  Author(s): J Vuori
  6.  *  Modification(s):
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <signal.h>
  12. #include <conio.h>
  13. #include <ctype.h>
  14. #include "dspldrv.h"
  15.  
  16. #define DX        512     // number of horisontal lines
  17. #define DY        256     // vertical lines
  18.  
  19. #define STEP        16
  20.  
  21.  
  22. static struct {
  23.     unsigned ctrlC:1;
  24.     unsigned reso:1;
  25. } flags;
  26. int data[512];
  27.  
  28. /*
  29.  * CTRL-C handler
  30.  */
  31. void cdecl CtrlCHandler(void) {
  32.     flags.ctrlC = 1;
  33. }
  34.  
  35.  
  36. static int nextl(FILE *fd, long *data) {
  37.     int  c;
  38.     char buff[80], *p;
  39.  
  40.     /* first flush leading space out */
  41.     p = buff;
  42.     while (c = getc(fd), !isdigit(c) && c != '-' && c != EOF);
  43.     *p++ = c;
  44.     if (c == EOF) return (EOF);
  45.  
  46.     /* then get the main body of the character */
  47.     while (c = getc(fd), c != EOF && (isdigit(c) || c == '-'))
  48.     *p++ = c;
  49.  
  50.     *p = '\0';
  51.  
  52.     *data = atol(buff) > 8388608L ? atol(buff)-16777216 : atol(buff);
  53.  
  54.     return (0);
  55. }
  56.  
  57.  
  58. int cdecl main(int argc, char *argv[]) {
  59.     FILE    *fd = NULL;
  60.     long    d, max = -2147483647, min = 2147483646;
  61.     int     i, j, c, val;
  62.  
  63.     //signal(SIGINT, CtrlCHandler);
  64.  
  65.     if (!(fd = fopen(argc < 2 ? "LOG.DAT" : *++argv, "r"))) {
  66.     fprintf(stderr, "can't open file '%s'\n", argc < 2 ? "LOG.DAT" : *argv);
  67.     return (1);
  68.     }
  69.     setvbuf(fd, NULL, _IOFBF, 8192);
  70.  
  71.     if (InitDspl(DX, DY)) {
  72.     fprintf(stderr, "%s: no support for needed graphics device\n", __FILE__);
  73.     return (1);
  74.     }
  75.  
  76.     /* serach max and min values */
  77.     while (nextl(fd, &d) != EOF) {
  78.     max = max(max, d);
  79.     min = min(min, d);
  80.     }
  81.     rewind(fd);
  82.  
  83.     c = ' '; j = 512;
  84.     do {
  85.     ErasePlot();
  86.  
  87.     if (c == 't') {
  88.         j           = 0;
  89.         flags.reso = !flags.reso;
  90.     }
  91.  
  92.     /* read a new block if needed */
  93.     if (j == 512) {
  94.         for (i = 0; i < 512; i++)
  95.         if (nextl(fd, &d) == EOF)
  96.             data[i] = 0;
  97.         else
  98.             data[i] = (int)(255.0*(d-min)/(max-min)+.5);
  99.         j = 0;
  100.     }
  101.  
  102.     for (i = 0; i < 512; i++) {
  103.         if (flags.reso ? !(i % STEP) : 1) {
  104.         val = data[j++];
  105.         if (flags.reso) PlotCircle(i, val);
  106.         }
  107.  
  108.         PlotLine(i, val);
  109.     }
  110.  
  111.     if (max > 0 && min < 0)
  112.         PlotZeroLine(-min*256L/(max-min));
  113.  
  114.     while(!kbhit());
  115.     } while ((c = getch()) != '.');
  116.  
  117. end:
  118.     ReleaseDspl();
  119.     return (0);
  120. }
  121.